typedef struct {
    int* array;
    int front;
    int fear;
    int n;
    int flag;
} MyCircularQueue;


MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* mq = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    if (!mq) {
        return NULL;
    }
    mq->n = k;
    mq->array = (int*)malloc(sizeof(int) * mq->n);
    if (!mq->array)
        return NULL;
    mq->front = 0;
    mq->fear = 0;
    mq->flag = 0;
    return mq;
}

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    assert(obj);
    return (obj->fear == obj->front) && (obj->flag == 0);
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    return (obj->fear == obj->front) && (obj->flag == 1);
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if (myCircularQueueIsFull(obj))
        return false;
    obj->array[(obj->fear)++] = value; 
    obj->fear %= obj->n;
    obj->flag = 1;
    return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return false;

    obj->front++;
    obj->front %= obj->n;
    obj->flag = 0;
    return true;
}

int myCircularQueueFront(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return -1;
    return obj->array[obj->front];
}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return -1;
    return obj->array[(obj->fear - 1 + obj->n) % (obj->n)];
}


void myCircularQueueFree(MyCircularQueue* obj) {
    if (obj->array) {
        free(obj->array);
        free(obj);
    }
}

/**
 * Your MyCircularQueue struct will be instantiated and called as such:
 * MyCircularQueue* obj = myCircularQueueCreate(k);
 * bool param_1 = myCircularQueueEnQueue(obj, value);

 * bool param_2 = myCircularQueueDeQueue(obj);

 * int param_3 = myCircularQueueFront(obj);

 * int param_4 = myCircularQueueRear(obj);

 * bool param_5 = myCircularQueueIsEmpty(obj);

 * bool param_6 = myCircularQueueIsFull(obj);

 * myCircularQueueFree(obj);
*/